public class MyCircularQueue {

    int[] queue;
    int first;
    int end;
    int k;
    public MyCircularQueue(int k) {
        queue = new int[k];
        first = -1;
        end = -1;
        this.k = k;
    }

    public boolean enQueue(int value) {
        if (isFull()) return false;
        if (isEmpty()) first = 0;
        end = (end + 1) % k;
        queue[end] = value;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) return false;
        if (first == end) {
            first = -1;
            end = -1;
        } else first = (first + 1) % k;
        return true;
    }

    public int Front() {
        if (isEmpty()) return -1;
        return queue[first];
    }

    public int Rear() {
        if (isEmpty()) return -1;
        return queue[end];
    }

    public boolean isEmpty() {
        return first == -1;
    }

    public boolean isFull() {
        return (end + 1) % k == first;
    }
}
